package cn.hpu.mobile_bank.config;


import cn.hpu.mobile_bank.interceptor.LoginInterceptor;
import cn.hpu.mobile_bank.interceptor.RefreshTokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    //增加拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //登录拦截器
        registry.addInterceptor(new LoginInterceptor(stringRedisTemplate))
                .excludePathPatterns(//放行的
                        "/user/code",
                        "/user/login",
                        "/user/register",
                        "/user/check",
                        "/swagger-resources/**",
                        "/webjars/**",
                        "/swagger-ui.html/**",
                        "/doc.html/**",
                        "/v2/**"
                ).order(1);
        // token刷新的拦截器
        registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate)).addPathPatterns("/**").order(0);
    }
}
